package com.zz.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zz.dao.CourseTopicDao;
import com.zz.domain.CourseTopic;
import com.zz.services.CourseTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CourseTopicServiceImpl implements CourseTopicService {

    @Autowired
    private CourseTopicDao courseTopicDao;
    //获取首页课程列表
    @Override
    public PageInfo<CourseTopic> getIndexCourseTopic(int type) {
        PageHelper.startPage(1,4);

        Map<String,Object> map = new HashMap<>();
        map.put("type_id",type);
        map.put("flag",1);
        List<CourseTopic> list =  courseTopicDao.findCourseTopicByCondition(map) ;
        PageInfo<CourseTopic> pageInfo = new PageInfo<>(list);
        return  pageInfo;
    }
    //获取首页最新课程
    @Override
    public PageInfo<CourseTopic> getIndexNewestTopic(int limit) {
        PageHelper.startPage(1,limit);
        Map<String,Object> map = new HashMap<>();
        map.put("flag",1);
        map.put("order",1);
        List<CourseTopic> list =  courseTopicDao.findCourseTopicByCondition(map);
        PageInfo<CourseTopic> pageInfo = new PageInfo<>(list);
        return  pageInfo;
    }
    // course_list.jsp 获取课程专题列表的数据
    @Override
    public PageInfo<CourseTopic> getCourseTopicList() {
        Map<String,Object> map = new HashMap<>() ;
        map.put("flag",1);  //只需要有效的
//        map.put("order",1);
        List<CourseTopic> courseTopicList =  courseTopicDao.findCourseTopicByCondition(map);
        return  new PageInfo<>(courseTopicList);
    }
    //course_list.jsp 根据课程分类寻找
    @Override
    public PageInfo<CourseTopic> getCourseTopicByTypeId(int typeId) {
        Map<String,Object>  map = new HashMap<>();
        map.put("flag",1);
        map.put("typeId",typeId);
        List<CourseTopic> courseTopicList = courseTopicDao.findCourseTopicByCondition(map);
        return  new PageInfo<>(courseTopicList);
    }

    // 根据 id 获取课程专题

    public  CourseTopic getCourseById(Integer topicId){
        Map<String,Object> map = new HashMap<>();
        List<Integer> list = new ArrayList<>();
        list.add(topicId);
        List<CourseTopic> topicList =  courseTopicDao.findCourseTopicByIds(list);
        return  topicList.get(0);
    }


}
